<template>
    <!-- <div class="blog-container">
        <nav class="navbar">
        <div class="container">
            <div class="nav-con">
                <div class="navbar-header">
                <h1 class="logo">蓝色博客</h1>
                </div>
                <ul class="nav-links" :class="{ 'active': menuActive }">
                <li><router-link to="/">首页</router-link></li>
                <li><router-link to="/articles">文章</router-link></li>
                <li><router-link to="/about">关于</router-link></li>
                </ul>
            </div>
        </div>
        </nav>
    </div> -->
    <header class="header">
        <div class="logo">{{ aboutInfo.aName }}</div>
        <div class="menu-toggle" tabindex="0" @click="menuClick" @blur="menuBlur">☰</div>
        <ul class="nav-links" :class="menuActive">
            <li><router-link to="/">首页</router-link></li>
            <li><router-link to="/articles">文章列表</router-link></li>
            <li><router-link to="/about">关于我&联系我</router-link></li>
        </ul>
    </header>
    <!--内容-->
    <router-view></router-view>
</template>

<script setup name="BlogHome">
import { useHead } from "@vueuse/head";
import { computed, onMounted, ref } from "vue";
import { getAbout } from "@/api/home"

const aboutInfo = ref({})
const menuActive = ref('')

function menuClick() {
    if(menuActive.value === ''){
        menuActive.value = 'menu-active'
    }else{
        menuActive.value = ''
    }
}

function menuBlur(){
    menuActive.value = ''
}

const seoData = computed(() => ({
  meta: [
    {
      name: 'description',
      content: '个人博客 - 空指针的夜晚网站首页，持续分享技术、生活、个人感悟等方面的文章，欢迎访问，感谢支持~' 
    },
    {
      name: 'keywords',
      content: '博客，个人博客，技术博客，IT技术分享，空指针的夜晚'
    }
  ]
}))

useHead(seoData)

const selectAbout = () => {
    let aboutObj = JSON.parse(localStorage.getItem('about'))
    if(aboutObj){
        aboutInfo.value = aboutObj
        return false
    }
    getAbout().then(response => {
        aboutInfo.value = response.data
        localStorage.setItem('about',JSON.stringify(aboutInfo.value))
    })
}

onMounted(() => {
    selectAbout()
})
</script>

<style>
/* 基础样式 */
:root {
    --primary-color: #3498db;
    --secondary-color: #2980b9;
    --light-color: #ecf0f1;
    --dark-color: #2c3e50;
    --text-color: #333;
    --light-text: #7f8c8d;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 50%;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text-color);
  line-height: 1.6;
  overflow-x: hidden;
  height: 100%;
}

        
.header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #333;
    color: white;
    padding: 15px 20px;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

/* 修复容器间距问题 */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
}

/* 手机端更紧凑的间距 - 重要修改 */
@media (max-width: 767px) {
  .container {
    padding: 0 10px;
  }
  
  .welcome-banner {
    padding: 2rem 0.5rem;
    margin-left: -10px;
    margin-right: -10px;
    border-radius: 0;
  }
}

.nav-con{
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* max-width: 1200px; */
    width: 100%;
}

.logo {
  margin: 0;
  color: var(--accent-color);
  font-size: 1.8rem;
  -webkit-user-select: none; /* Chrome/Safari */
  -moz-user-select: none;    /* Firefox */
  -ms-user-select: none;     /* IE10+ */
  user-select: none;         /* 标准语法 */
}

/* 默认隐藏移动端菜单按钮 */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
}

.nav-links {
    display: flex;
    list-style: none;
}

.nav-links li {
    margin-left: 20px;
}

.nav-links a {
    color: white;
    text-decoration: none;
    transition: color 0.3s;
}

.nav-links a:hover {
    color: #4CAF50;
}



/* 响应式设计 */
@media (max-width: 768px) {
    .header {
        padding: 10px 15px;
    }
    
    .nav-links {
        position: fixed;
        top: 60px;
        left: 100%;
        width: 50%;
        height: calc(100vh - 60px);
        background-color: #333;
        flex-direction: column;
        align-items: center;
        padding-top: 20px;
        transition: left 0.3s ease;
    }
    
    .nav-links.active {
        left: 0;
    }
    
    .nav-links li {
        margin: 15px 0;
    }
    
    .menu-toggle {
        display: block;
    }

    .menu-active{
        position: fixed;
        left: 50%;
    }
}

@media (max-width: 480px) {
    .logo {
        font-size: 1.2rem;
    }
    
    .header {
        padding: 8px 10px;
    }
}

/* 设置进度条颜色 */
#nprogress .bar {
  background: #4CAF50 !important;
}
</style>